#include "process.h"

void progress_bar1()
{
    char buff[NUM];
    memset(buff, 0, NUM);
    const char* lable = "|/-\\";
    int len = strlen(lable);

    int cnt = 0;
    while(cnt < NUM)
    {
        printf("[%-100s][%d%%][%c]\r", buff, cnt, lable[cnt % len]);
        fflush(stdout);
        usleep(30000);
        buff[cnt] = STYLE;
        ++cnt;
    }
    printf("\n");
}

void progress_bar2(double total, double cur)
{
    static int cnt = 0; // 用于记录调用的次数
    ++cnt;
    char buff[NUM];
    memset(buff, 0, NUM);
    const char* lable = "|/-\\";
    int len = strlen(lable);

    double rate = cur / total * 100;
    int num = (int)rate;
    for(int i = 0; i < num; ++i)
    {
        buff[i] = STYLE;
    }

    printf("[%-100s][%.2lf%%][%c]\r", buff, rate, lable[cnt % len]);
    fflush(stdout);
}
